home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / crc.swg / 0014_CheckSums in BASM.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  785b  |  35 lines

  1. (* ===========================================================================
  2. Date: 09-29-93 (11:16)
  3. From: HELGE HELGESEN
  4. Subj: Checksums?
  5.  
  6.        How does one compute simple checksums? For example for a byte
  7.        sequence $8A $05 $7E $1C, what would the checksum be? Where
  8.        could I get some info on this?
  9.  
  10. Here's one that simply adds each byte together and sends back the
  11. result:
  12. ===========================================================================*)
  13.  
  14. function MakeCheckSum(p: pointer; length: word): byte; assembler;
  15. asm
  16.   cld
  17.   push ds
  18.   xor  ah, ah
  19.   mov  cx, length
  20.   jcxz @x
  21.   lds  si, p
  22. @1:
  23.   lodsb
  24.   add  ah, al
  25.   loop @1
  26. @x:
  27.   pop  ds
  28.   mov  al, ah
  29. end;
  30.  
  31. So you call this like this:
  32.  
  33. x:=MakeCheckSum(@myvar, length_of_var);
  34.  
  35.